//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.media;

import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore.Audio.Media;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class AudioProvider {
    private Context context;

    public AudioProvider(Context context) {
        this.context = context;
    }

    public List<Audio> getList() {
        List<Audio> list = null;
        if(this.context != null) {
            Cursor cursor = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, (String[])null, (String)null, (String[])null, (String)null);
            if(cursor != null) {
                list = new ArrayList();

                while(cursor.moveToNext()) {
                    int id = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
                    String title = cursor.getString(cursor.getColumnIndexOrThrow("title"));
                    String album = cursor.getString(cursor.getColumnIndexOrThrow("album"));
                    String artist = cursor.getString(cursor.getColumnIndexOrThrow("artist"));
                    String path = cursor.getString(cursor.getColumnIndexOrThrow("_data"));
                    String displayName = cursor.getString(cursor.getColumnIndexOrThrow("_display_name"));
                    String mimeType = cursor.getString(cursor.getColumnIndexOrThrow("mime_type"));
                    long duration = (long)cursor.getInt(cursor.getColumnIndexOrThrow("duration"));
                    long size = cursor.getLong(cursor.getColumnIndexOrThrow("_size"));
                    Audio audio = new Audio(id, title, album, artist, path, displayName, mimeType, duration, size);
                    list.add(audio);
                }

                cursor.close();
            }
        }

        return list;
    }

    public Map<String, ArrayList<Audio>> getFolderMap() {
        Map<String, ArrayList<Audio>> map = new HashMap();
        List<Audio> list = this.getList();
        if(list != null) {
            Iterator var4 = list.iterator();

            while(var4.hasNext()) {
                Audio audio = (Audio)var4.next();
                String folderPath = audio.getPath().substring(0, audio.getPath().lastIndexOf(File.separator));
                ArrayList imageList;
                if(map.containsKey(folderPath)) {
                    imageList = (ArrayList)map.get(folderPath);
                    imageList.add(audio);
                    map.put(folderPath, imageList);
                } else {
                    imageList = new ArrayList();
                    imageList.add(audio);
                    map.put(folderPath, imageList);
                }
            }
        }

        return map;
    }
}
